﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CheckBoxAdapter.cs" company="">
//   
// </copyright>
// <summary>
//   The check box adapter.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Adapters
{
    using System;
    using System.Windows.Forms;

    using Libium.Views;

    /// <summary>
    /// The check box adapter.
    /// </summary>
    public class CheckBoxAdapter : DisabledWhenReadonlyControlAdapter<CheckBox>, ICheckView
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CheckBoxAdapter"/> class.
        /// </summary>
        /// <param name="checkBox">
        /// The check box.
        /// </param>
        public CheckBoxAdapter(CheckBox checkBox)
            : base(checkBox)
        {
            Control.CheckedChanged += OnCheckedChanged;
        }

        #endregion

        #region Public Events

        /// <summary>
        /// The is checked changed.
        /// </summary>
        public event Action<ICheckView> IsCheckedChanged;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets a value indicating whether is checked.
        /// </summary>
        public bool IsChecked
        {
            get
            {
                return Control.Checked;
            }

            set
            {
                Control.Checked = value;
            }
        }
             
        #endregion

        #region Methods

        /// <summary>
        /// The on checked changed.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected virtual void OnCheckedChanged(object source, EventArgs e)
        {
            if (IsCheckedChanged != null)
            {
                IsCheckedChanged(this);
            }
        }

        #endregion
    }
}